package cn.jee.spring_jdbc.dao.mapper;


import domain.Stu;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface StuDAOByMybatis extends StuDao {
    @Select("select * from stu where id=#{id}")
    public Stu findById(@Param("id") long id);


    @Select("select * from stu")
    public List<Stu> findAll();

    /**列名=值*/
    @Select("select * from stu")
    List<Map> findAllByMap();


    @Insert("insert into stu (username,pass,java,math,os) values(#{stu.username},#{stu.pass},#{stu.java}," +
            "#{stu.math},#{stu.os})")
    @Options(useGeneratedKeys = true,keyProperty = "stu.id")
    int add(@Param("stu") Stu stu);

    @Insert("insert into stu (username,pass,java,math,os) values(#{username},#{pass},#{java}," +
            "#{math},#{os})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int add2(Stu stu);

    @Select("select * from stu where username=#{username} and pass=#{pass}")
    List<Stu> checkLogin(@Param("username") String username,@Param("pass") String passs);
    @Select("select count(*) from stu where username=#{username} and pass=#{pass}")
    int checkLogin2(@Param("username") String username,@Param("pass") String pass);

}
